<!doctype html>
<html lang="zh-CN">
<head>
  <base href="https://www.nodeapp.cn/tls.html" />
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>安全传输层（TLS/SSL） | Node.js 中文文档 | Node.js 中文网</title>
  <meta name="description" content="Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型，使其轻量又高效。Node.js 的包管理器 npm，是全球最大的开源库生态系统。">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://www.nodeapp.cn/tls.html">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <link rel="icon" sizes="32x32" type="image/png" href="favicon.png">
  
  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?acdf78480f7f8f2b23b812565a5868e0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>
<body class="alt apidoc" id="api-section-tls">
  <div id="content" class="clearfix">
    <div id="column1" data-id="tls" class="interior">
      <header>
        <h1>Node.js v8.x 中文文档</h1>
        <hr>
      </header>

      <div id="toc">
        <h2>目录</h2>
        <ul>
<li><span class="stability_2"><a href="#tls_tls_ssl">tls (安全传输层)</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_tls_ssl_concepts">TLS/SSL 概念</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_perfect_forward_secrecy">Perfect Forward Secrecy</a></span></li>
<li><span class="stability_undefined"><a href="#tls_alpn_npn_and_sni">ALPN, NPN, and SNI</a></span></li>
<li><span class="stability_undefined"><a href="#tls_client_initiated_renegotiation_attack_mitigation">Client-initiated renegotiation attack mitigation</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#tls_modifying_the_default_tls_cipher_suite">Modifying the Default TLS Cipher suite</a></span></li>
<li><span class="stability_undefined"><a href="#tls_class_tls_server">Class: tls.Server</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_event_newsession">Event: &apos;newSession&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_ocsprequest">Event: &apos;OCSPRequest&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_resumesession">Event: &apos;resumeSession&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_secureconnection">Event: &apos;secureConnection&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_tlsclienterror">Event: &apos;tlsClientError&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_addcontext_hostname_context">server.addContext(hostname, context)</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_address">server.address()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_close_callback">server.close([callback])</a></span></li>
<li><span class="stability_0"><a href="#tls_server_connections">server.connections</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_getticketkeys">server.getTicketKeys()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_listen">server.listen()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_server_setticketkeys_keys">server.setTicketKeys(keys)</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#tls_class_tls_tlssocket">Class: tls.TLSSocket</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_new_tls_tlssocket_socket_options">new tls.TLSSocket(socket[, options])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_ocspresponse">Event: &apos;OCSPResponse&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_event_secureconnect">Event: &apos;secureConnect&apos;</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_address">tlsSocket.address()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_authorizationerror">tlsSocket.authorizationError</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_authorized">tlsSocket.authorized</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_disablerenegotiation">tlsSocket.disableRenegotiation()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_encrypted">tlsSocket.encrypted</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_getcipher">tlsSocket.getCipher()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_getephemeralkeyinfo">tlsSocket.getEphemeralKeyInfo()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_getpeercertificate_detailed">tlsSocket.getPeerCertificate([detailed])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_getprotocol">tlsSocket.getProtocol()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_getsession">tlsSocket.getSession()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_gettlsticket">tlsSocket.getTLSTicket()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_localaddress">tlsSocket.localAddress</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_localport">tlsSocket.localPort</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_remoteaddress">tlsSocket.remoteAddress</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_remotefamily">tlsSocket.remoteFamily</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_remoteport">tlsSocket.remotePort</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_renegotiate_options_callback">tlsSocket.renegotiate(options, callback)</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tlssocket_setmaxsendfragment_size">tlsSocket.setMaxSendFragment(size)</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#tls_tls_checkserveridentity_host_cert">tls.checkServerIdentity(host, cert)</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_connect_options_callback">tls.connect(options[, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_connect_path_options_callback">tls.connect(path[, options][, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_connect_port_host_options_callback">tls.connect(port[, host][, options][, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_createsecurecontext_options">tls.createSecureContext(options)</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_createserver_options_secureconnectionlistener">tls.createServer([options][, secureConnectionListener])</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_getciphers">tls.getCiphers()</a></span></li>
<li><span class="stability_undefined"><a href="#tls_tls_default_ecdh_curve">tls.DEFAULT_ECDH_CURVE</a></span></li>
<li><span class="stability_undefined"><a href="#tls_deprecated_apis">Deprecated APIs</a></span><ul>
<li><span class="stability_0"><a href="#tls_class_cryptostream">Class: CryptoStream</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_cryptostream_byteswritten">cryptoStream.bytesWritten</a></span></li>
</ul>
</li>
<li><span class="stability_0"><a href="#tls_class_securepair">Class: SecurePair</a></span><ul>
<li><span class="stability_undefined"><a href="#tls_event_secure">Event: &apos;secure&apos;</a></span></li>
</ul>
</li>
<li><span class="stability_0"><a href="#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options">tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>
<div id="apicontent">
        <h1>tls (安全传输层)<span><a class="mark" href="#tls_tls_ssl" id="tls_tls_ssl">#</a></span></h1>
<!--introduced_in=v0.10.0-->
<div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">稳定性: 2</a> - 稳定的</div><p><code>tls</code> 模块是对安全传输层（TLS）及安全套接层（SSL）协议的实现，建立在OpenSSL的基础上。
按如下方式引用此模块:</p>
<pre><code class="lang-js">const tls = require(&apos;tls&apos;);
</code></pre>
<h2>TLS/SSL 概念<span><a class="mark" href="#tls_tls_ssl_concepts" id="tls_tls_ssl_concepts">#</a></span></h2>
<p>TLS/SSL是public/private key infrastructure (PKI).大部分情况下，每个服务器和客户端都应该有一个<em>私钥</em>。</p>
<p>私钥能有多种生成方式，下面举一个例子。
用OpenSSL的命令行来生成一个2048位的RSA私钥：</p>
<pre><code class="lang-sh">openssl genrsa -out ryans-key.pem 2048
</code></pre>
<p>通过TLS/SSL,所有的服务器（和一些客户端）必须要一个<em>证书</em>。
证书是相似于私钥的<em>公钥</em>,它由CA或者私钥拥有者数字签名，特别地，私钥拥有者所签名的被称为自签名。
获取证书的第一步是生成一个<em>证书申请文件（CSR)</em></p>
<p>用OpenSSL能生成一个私钥的CSR文件：</p>
<pre><code class="lang-sh">openssl req -new -sha256 -key ryans-key.pem -out ryans-csr.pem
</code></pre>
<p>CSR文件被生成以后，它既能被CA签名也能被用户自签名。
用OpenSSL生成一个自签名证书的命令如下：</p>
<pre><code class="lang-sh">openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem
</code></pre>
<p>证书被生成以后，它又能用来生成一个<code>.pfx</code>或者<code>.p12</code>文件：</p>
<pre><code class="lang-sh">openssl pkcs12 -export -in ryans-cert.pem -inkey ryans-key.pem \
      -certfile ca-cert.pem -out ryans.pfx
</code></pre>
<p>命令行参数:</p>
<ul>
<li><code>in</code>: 被签名的证书</li>
<li><code>inkey</code>: 有关的私钥</li>
<li><code>certfile</code>: 签入文件的证书串，比如： <code>cat ca1-cert.pem ca2-cert.pem &gt; ca-cert.pem</code></li>
</ul>
<h3>Perfect Forward Secrecy<span><a class="mark" href="#tls_perfect_forward_secrecy" id="tls_perfect_forward_secrecy">#</a></span></h3>
<!-- type=misc -->
<p>术语“前向保密”或“[完全前向保密]”是一种密钥协商（或称做密钥交换）方法.
通过这种方法,客户端与服务端在当前会话中,协商一个临时生成的密钥进行对称加密的密钥交换.
这意味着即使服务器端私钥发生泄漏,窃密者与攻击者也无法解密通信内容,除非他们能得到当前会话的临时密钥.</p>
<p>TLS/SSL 握手时,使用完全前向即每次会话都会随机生成一个临时密钥对用于对称加密密钥协商(区别于每次会话都是用相同的密钥).
实现这个技术的密钥交换算法都带有一个E,即ephemeral.</p>
<p>当前最常用的两种实现完全前向保密的算法(注意算法结尾的&quot;E&quot;):</p>
<ul>
<li>[DHE] - 使用临时密钥的Diffie Hellman密钥交换算法.</li>
<li>[ECDHE] - 使用临时密钥的椭圆曲线Diffie Hellman密钥交换算法.</li>
</ul>
<p>使用临时密钥会带来性能损失,因为密钥生成的过程十分消耗CPU计算性能.</p>
<p>如需使用完全前向加密,例如使用<code>tls</code>模块的<code>DHE</code>算法,使用之前需要生成一个Diffie-Hellman
参数并将其用<code>dhparam</code>声明在[<code>tls.createSecureContext()</code>][]中.如下例子展示了如何使用
OpenSSL命令生成参数:</p>
<pre><code class="lang-sh">openssl dhparam -outform PEM -out dhparam.pem 2048
</code></pre>
<p>如需使用<code>ECDHE</code>算法,则不需要生成Diffie-Hellman参数,因为可以使用默认的ECDHE曲线.
在创建TLS Server时,可使用<code>ecdhCurve</code>属性声明服务器支持的曲线名词.详请参考[<code>tls.createServer()</code>].</p>
<h3>ALPN, NPN, and SNI<span><a class="mark" href="#tls_alpn_npn_and_sni" id="tls_alpn_npn_and_sni">#</a></span></h3>
<!-- type=misc -->
<p>ALPN (Application-Layer Protocol Negotiation Extension,应用层协议协商),
NPN (Next Protocol Negotiation,下一代协议协商) , 
SNI (Server Name Indication,服务器名称指示)是三个TLS拓展:</p>
<ul>
<li>ALPN/NPN - 允许一个TLS服务器使用多个版本的HTTP协议 (HTTP, SPDY, HTTP/2).</li>
<li>SNI - 允许一个TLS服务器支持多个主机名以及证书.</li>
</ul>
<p><em>注意</em>: 应优先使用ALPN而非NPN,因为NPN拓展从未正式定义或记录,一般不建议使用.</p>
<h3>Client-initiated renegotiation attack mitigation<span><a class="mark" href="#tls_client_initiated_renegotiation_attack_mitigation" id="tls_client_initiated_renegotiation_attack_mitigation">#</a></span></h3>
<!-- type=misc -->
<p>TLS协议允许客户端在TLS会话中进行重协商,用于安全因素的考量.
不幸的是,会话重协商需要消耗大量的服务器端资源,这将导致服务器存在潜在的被DDoS攻击的可能.</p>
<p>为了减轻这个风险,node限制每十分钟只能使用三次重协商,超过这个限制将会在[<code>tls.TLSSocket</code>][]实例中产生一个<code>error</code>事件.
这个限制是可配置的:</p>
<ul>
<li><code>tls.CLIENT_RENEG_LIMIT</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 指定重协商请求的次数限制,默认为<code>3</code>.</li>
<li><code>tls.CLIENT_RENEG_WINDOW</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 指定限制次数的生效时间段,默认是<code>600</code>(十分钟).</li>
</ul>
<p><em>注意</em>:   不应在未充分理解其含义与影响的情况下修改上述参数.</p>
<p>如果要测试服务端重协商限制,请使用OpenSSL命令行客户端(<code>openssl s_client -connect address:port</code>)连接服务器,并输入
<code>R&lt;CR&gt;</code> (即输入R字符后紧跟回车) 多次,如在默认配置下连接服务器并输入三次<code>R</code>加回车后,服务器断开了连接,则表示限制生效.</p>
<h2>Modifying the Default TLS Cipher suite<span><a class="mark" href="#tls_modifying_the_default_tls_cipher_suite" id="tls_modifying_the_default_tls_cipher_suite">#</a></span></h2>
<p>Node.js is built with a default suite of enabled and disabled TLS ciphers.
Currently, the default cipher suite is:</p>
<pre><code class="lang-txt">ECDHE-RSA-AES128-GCM-SHA256:
ECDHE-ECDSA-AES128-GCM-SHA256:
ECDHE-RSA-AES256-GCM-SHA384:
ECDHE-ECDSA-AES256-GCM-SHA384:
DHE-RSA-AES128-GCM-SHA256:
ECDHE-RSA-AES128-SHA256:
DHE-RSA-AES128-SHA256:
ECDHE-RSA-AES256-SHA384:
DHE-RSA-AES256-SHA384:
ECDHE-RSA-AES256-SHA256:
DHE-RSA-AES256-SHA256:
HIGH:
!aNULL:
!eNULL:
!EXPORT:
!DES:
!RC4:
!MD5:
!PSK:
!SRP:
!CAMELLIA
</code></pre>
<p>This default can be replaced entirely using the <code>--tls-cipher-list</code> command
line switch. For instance, the following makes
<code>ECDHE-RSA-AES128-GCM-SHA256:!RC4</code> the default TLS cipher suite:</p>
<pre><code class="lang-sh">node --tls-cipher-list=&quot;ECDHE-RSA-AES128-GCM-SHA256:!RC4&quot;
</code></pre>
<p>The default can also be replaced on a per client or server basis using the
<code>ciphers</code> option from [<code>tls.createSecureContext()</code>][], which is also available
in [<code>tls.createServer()</code>], [<code>tls.connect()</code>], and when creating new
[<code>tls.TLSSocket</code>]s.</p>
<p>Consult [OpenSSL cipher list format documentation][] for details on the format.</p>
<p><em>Note</em>: The default cipher suite included within Node.js has been carefully
selected to reflect current security best practices and risk mitigation.
Changing the default cipher suite can have a significant impact on the security
of an application. The <code>--tls-cipher-list</code> switch and <code>ciphers</code> option should by
used only if absolutely necessary.</p>
<p>The default cipher suite prefers GCM ciphers for [Chrome&apos;s &apos;modern
cryptography&apos; setting] and also prefers ECDHE and DHE ciphers for Perfect
Forward Secrecy, while offering <em>some</em> backward compatibility.</p>
<p>128 bit AES is preferred over 192 and 256 bit AES in light of [specific
attacks affecting larger AES key sizes].</p>
<p>Old clients that rely on insecure and deprecated RC4 or DES-based ciphers
(like Internet Explorer 6) cannot complete the handshaking process with
the default configuration. If these clients <em>must</em> be supported, the
[TLS recommendations] may offer a compatible cipher suite. For more details
on the format, see the [OpenSSL cipher list format documentation].</p>
<h2>Class: tls.Server<span><a class="mark" href="#tls_class_tls_server" id="tls_class_tls_server">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.3.2</span>
</div><p>The <code>tls.Server</code> class is a subclass of <code>net.Server</code> that accepts encrypted
connections using TLS or SSL.</p>
<h3>Event: &apos;newSession&apos;<span><a class="mark" href="#tls_event_newsession" id="tls_event_newsession">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.9.2</span>
</div><p>The <code>&apos;newSession&apos;</code> event is emitted upon creation of a new TLS session. This may
be used to store sessions in external storage. The listener callback is passed
three arguments when called:</p>
<ul>
<li><code>sessionId</code> - The TLS session identifier</li>
<li><code>sessionData</code> - The TLS session data</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function taking no arguments that must be
invoked in order for data to be sent or received over the secure connection.</li>
</ul>
<p><em>Note</em>: Listening for this event will have an effect only on connections
established after the addition of the event listener.</p>
<h3>Event: &apos;OCSPRequest&apos;<span><a class="mark" href="#tls_event_ocsprequest" id="tls_event_ocsprequest">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.13</span>
</div><p>The <code>&apos;OCSPRequest&apos;</code> event is emitted when the client sends a certificate status
request. The listener callback is passed three arguments when called:</p>
<ul>
<li><code>certificate</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The server certificate</li>
<li><code>issuer</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The issuer&apos;s certificate</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function that must be invoked to provide
the results of the OCSP request.</li>
</ul>
<p>The server&apos;s current certificate can be parsed to obtain the OCSP URL
and certificate ID; after obtaining an OCSP response, <code>callback(null, resp)</code> is
then invoked, where <code>resp</code> is a <code>Buffer</code> instance containing the OCSP response.
Both <code>certificate</code> and <code>issuer</code> are <code>Buffer</code> DER-representations of the
primary and issuer&apos;s certificates. These can be used to obtain the OCSP
certificate ID and OCSP endpoint URL.</p>
<p>Alternatively, <code>callback(null, null)</code> may be called, indicating that there was
no OCSP response.</p>
<p>Calling <code>callback(err)</code> will result in a <code>socket.destroy(err)</code> call.</p>
<p>The typical flow of an OCSP Request is as follows:</p>
<ol>
<li>Client connects to the server and sends an <code>&apos;OCSPRequest&apos;</code> (via the status
info extension in ClientHello).</li>
<li>Server receives the request and emits the <code>&apos;OCSPRequest&apos;</code> event, calling the
listener if registered.</li>
<li>Server extracts the OCSP URL from either the <code>certificate</code> or <code>issuer</code> and
performs an [OCSP request] to the CA.</li>
<li>Server receives <code>OCSPResponse</code> from the CA and sends it back to the client
via the <code>callback</code> argument</li>
<li>Client validates the response and either destroys the socket or performs a
handshake.</li>
</ol>
<p><em>Note</em>: The <code>issuer</code> can be <code>null</code> if the certificate is either self-signed or
the issuer is not in the root certificates list. (An issuer may be provided
via the <code>ca</code> option when establishing the TLS connection.)</p>
<p><em>Note</em>: Listening for this event will have an effect only on connections
established after the addition of the event listener.</p>
<p><em>Note</em>: An npm module like [asn1.js] may be used to parse the certificates.</p>
<h3>Event: &apos;resumeSession&apos;<span><a class="mark" href="#tls_event_resumesession" id="tls_event_resumesession">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.9.2</span>
</div><p>The <code>&apos;resumeSession&apos;</code> event is emitted when the client requests to resume a
previous TLS session. The listener callback is passed two arguments when
called:</p>
<ul>
<li><code>sessionId</code> - The TLS/SSL session identifier</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function to be called when the prior session
has been recovered.</li>
</ul>
<p>When called, the event listener may perform a lookup in external storage using
the given <code>sessionId</code> and invoke <code>callback(null, sessionData)</code> once finished. If
the session cannot be resumed (i.e., doesn&apos;t exist in storage) the callback may
be invoked as <code>callback(null, null)</code>. Calling <code>callback(err)</code> will terminate the
incoming connection and destroy the socket.</p>
<p><em>Note</em>: Listening for this event will have an effect only on connections
established after the addition of the event listener.</p>
<p>The following illustrates resuming a TLS session:</p>
<pre><code class="lang-js">const tlsSessionStore = {};
server.on(&apos;newSession&apos;, (id, data, cb) =&gt; {
  tlsSessionStore[id.toString(&apos;hex&apos;)] = data;
  cb();
});
server.on(&apos;resumeSession&apos;, (id, cb) =&gt; {
  cb(null, tlsSessionStore[id.toString(&apos;hex&apos;)] || null);
});
</code></pre>
<h3>Event: &apos;secureConnection&apos;<span><a class="mark" href="#tls_event_secureconnection" id="tls_event_secureconnection">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.2</span>
</div><p>The <code>&apos;secureConnection&apos;</code> event is emitted after the handshaking process for a
new connection has successfully completed. The listener callback is passed a
single argument when called:</p>
<ul>
<li><code>tlsSocket</code> 
            <a href="tls.html#tls_class_tls_tlssocket" class="type">&lt;tls.TLSSocket&gt;</a> The established TLS socket.</li>
</ul>
<p>The <code>tlsSocket.authorized</code> property is a <code>boolean</code> indicating whether the
client has been verified by one of the supplied Certificate Authorities for the
server. If <code>tlsSocket.authorized</code> is <code>false</code>, then <code>socket.authorizationError</code>
is set to describe how authorization failed. Note that depending on the settings
of the TLS server, unauthorized connections may still be accepted.</p>
<p>The <code>tlsSocket.npnProtocol</code> and <code>tlsSocket.alpnProtocol</code> properties are strings
that contain the selected NPN and ALPN protocols, respectively. When both NPN
and ALPN extensions are received, ALPN takes precedence over NPN and the next
protocol is selected by ALPN.</p>
<p>When ALPN has no selected protocol, <code>tlsSocket.alpnProtocol</code> returns <code>false</code>.</p>
<p>The <code>tlsSocket.servername</code> property is a string containing the server name
requested via SNI.</p>
<h3>Event: &apos;tlsClientError&apos;<span><a class="mark" href="#tls_event_tlsclienterror" id="tls_event_tlsclienterror">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v6.0.0</span>
</div><p>The <code>&apos;tlsClientError&apos;</code> event is emitted when an error occurs before a secure
connection is established. The listener callback is passed two arguments when
called:</p>
<ul>
<li><code>exception</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a> The <code>Error</code> object describing the error</li>
<li><code>tlsSocket</code> 
            <a href="tls.html#tls_class_tls_tlssocket" class="type">&lt;tls.TLSSocket&gt;</a> The <code>tls.TLSSocket</code> instance from which the
error originated.</li>
</ul>
<h3>server.addContext(hostname, context)<span><a class="mark" href="#tls_server_addcontext_hostname_context" id="tls_server_addcontext_hostname_context">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.5.3</span>
</div><ul>
<li><code>hostname</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A SNI hostname or wildcard (e.g. <code>&apos;*&apos;</code>)</li>
<li><code>context</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> An object containing any of the possible properties
from the [<code>tls.createSecureContext()</code>][] <code>options</code> arguments (e.g. <code>key</code>,
<code>cert</code>, <code>ca</code>, etc).</li>
</ul>
<p>The <code>server.addContext()</code> method adds a secure context that will be used if
the client request&apos;s SNI hostname matches the supplied <code>hostname</code> (or wildcard).</p>
<h3>server.address()<span><a class="mark" href="#tls_server_address" id="tls_server_address">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.6.0</span>
</div><p>Returns the bound address, the address family name, and port of the
server as reported by the operating system.  See [<code>net.Server.address()</code>][] for
more information.</p>
<h3>server.close([callback])<span><a class="mark" href="#tls_server_close_callback" id="tls_server_close_callback">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.2</span>
</div><ul>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> An optional listener callback that will be registered to
listen for the server instance&apos;s <code>&apos;close&apos;</code> event.</li>
</ul>
<p>The <code>server.close()</code> method stops the server from accepting new connections.</p>
<p>This function operates asynchronously. The <code>&apos;close&apos;</code> event will be emitted
when the server has no more open connections.</p>
<h3>server.connections<span><a class="mark" href="#tls_server_connections" id="tls_server_connections">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.2</span><span>废弃于: v0.9.7</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use [<code>server.getConnections()</code>][] instead.</div><p>Returns the current number of concurrent connections on the server.</p>
<h3>server.getTicketKeys()<span><a class="mark" href="#tls_server_getticketkeys" id="tls_server_getticketkeys">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v3.0.0</span>
</div><p>Returns a <code>Buffer</code> instance holding the keys currently used for
encryption/decryption of the [TLS Session Tickets][]</p>
<h3>server.listen()<span><a class="mark" href="#tls_server_listen" id="tls_server_listen">#</a></span></h3>
<p>Starts the server listening for encrypted connections.
This method is identical to [<code>server.listen()</code>][] from [<code>net.Server</code>][].</p>
<h3>server.setTicketKeys(keys)<span><a class="mark" href="#tls_server_setticketkeys_keys" id="tls_server_setticketkeys_keys">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v3.0.0</span>
</div><ul>
<li><code>keys</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The keys used for encryption/decryption of the
[TLS Session Tickets][].</li>
</ul>
<p>Updates the keys for encryption/decryption of the [TLS Session Tickets][].</p>
<p><em>Note</em>: The key&apos;s <code>Buffer</code> should be 48 bytes long. See <code>ticketKeys</code> option in
<a href="#tls_tls_createserver_options_secureconnectionlistener">tls.createServer</a> for
more information on how it is used.</p>
<p><em>Note</em>: Changes to the ticket keys are effective only for future server
connections. Existing or currently pending server connections will use the
previous keys.</p>
<h2>Class: tls.TLSSocket<span><a class="mark" href="#tls_class_tls_tlssocket" id="tls_class_tls_tlssocket">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>The <code>tls.TLSSocket</code> is a subclass of [<code>net.Socket</code>][] that performs transparent
encryption of written data and all required TLS negotiation.</p>
<p>Instances of <code>tls.TLSSocket</code> implement the duplex [Stream][] interface.</p>
<p><em>Note</em>: Methods that return TLS connection metadata (e.g.
[<code>tls.TLSSocket.getPeerCertificate()</code>][] will only return data while the
connection is open.</p>
<h3>new tls.TLSSocket(socket[, options])<span><a class="mark" href="#tls_new_tls_tlssocket_socket_options" id="tls_new_tls_tlssocket_socket_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v5.0.0</td>
<td><p>ALPN options are supported now.</p>
</td></tr>
<tr><td>v0.11.4</td>
<td><p><span>新增于: v0.11.4</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>socket</code> 
            <a href="net.html#net_class_net_socket" class="type">&lt;net.Socket&gt;</a> | 
            <a href="stream.html#stream_class_stream_duplex" class="type">&lt;stream.Duplex&gt;</a>
On the server side, any <code>Duplex</code> stream. On the client side, any
instance of [<code>net.Socket</code>][] (for generic <code>Duplex</code> stream support
on the client side, [<code>tls.connect()</code>][] must be used).</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>isServer</code>: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
they are to behave as a server or a client. If <code>true</code> the TLS socket will be
instantiated as a server.  Defaults to <code>false</code>.</li>
<li><code>server</code> <span class="type">&lt;net.Server&gt;</span> An optional [<code>net.Server</code>][] instance.</li>
<li><code>requestCert</code>: Whether to authenticate the remote peer by requesting a
 certificate. Clients always request a server certificate. Servers
 (<code>isServer</code> is true) may optionally set <code>requestCert</code> to true to request a
 client certificate.</li>
<li><code>rejectUnauthorized</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>NPNProtocols</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>ALPNProtocols</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>SNICallback</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>session</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> An optional <code>Buffer</code> instance containing a TLS session.</li>
<li><code>requestOCSP</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code>, specifies that the OCSP status request
extension will be added to the client hello and an <code>&apos;OCSPResponse&apos;</code> event
will be emitted on the socket before establishing a secure communication</li>
<li><code>secureContext</code>: Optional TLS context object created with
[<code>tls.createSecureContext()</code>][]. If a <code>secureContext</code> is <em>not</em> provided, one
will be created by passing the entire <code>options</code> object to
<code>tls.createSecureContext()</code>.</li>
<li>...: Optional [<code>tls.createSecureContext()</code>][] options that are used if the
<code>secureContext</code> option is missing, otherwise they are ignored.</li>
</ul>
</li>
</ul>
<p>Construct a new <code>tls.TLSSocket</code> object from an existing TCP socket.</p>
<h3>Event: &apos;OCSPResponse&apos;<span><a class="mark" href="#tls_event_ocspresponse" id="tls_event_ocspresponse">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.13</span>
</div><p>The <code>&apos;OCSPResponse&apos;</code> event is emitted if the <code>requestOCSP</code> option was set
when the <code>tls.TLSSocket</code> was created and an OCSP response has been received.
The listener callback is passed a single argument when called:</p>
<ul>
<li><code>response</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> The server&apos;s OCSP response</li>
</ul>
<p>Typically, the <code>response</code> is a digitally signed object from the server&apos;s CA that
contains information about server&apos;s certificate revocation status.</p>
<h3>Event: &apos;secureConnect&apos;<span><a class="mark" href="#tls_event_secureconnect" id="tls_event_secureconnect">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>The <code>&apos;secureConnect&apos;</code> event is emitted after the handshaking process for a new
connection has successfully completed. The listener callback will be called
regardless of whether or not the server&apos;s certificate has been authorized. It
is the client&apos;s responsibility to check the <code>tlsSocket.authorized</code> property to
determine if the server certificate was signed by one of the specified CAs. If
<code>tlsSocket.authorized === false</code>, then the error can be found by examining the
<code>tlsSocket.authorizationError</code> property. If either ALPN or NPN was used,
the <code>tlsSocket.alpnProtocol</code> or <code>tlsSocket.npnProtocol</code> properties can be
checked to determine the negotiated protocol.</p>
<h3>tlsSocket.address()<span><a class="mark" href="#tls_tlssocket_address" id="tls_tlssocket_address">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the bound address, the address family name, and port of the
underlying socket as reported by the operating system. Returns an
object with three properties, e.g.
<code>{ port: 12346, family: &apos;IPv4&apos;, address: &apos;127.0.0.1&apos; }</code></p>
<h3>tlsSocket.authorizationError<span><a class="mark" href="#tls_tlssocket_authorizationerror" id="tls_tlssocket_authorizationerror">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the reason why the peer&apos;s certificate was not been verified. This
property is set only when <code>tlsSocket.authorized === false</code>.</p>
<h3>tlsSocket.authorized<span><a class="mark" href="#tls_tlssocket_authorized" id="tls_tlssocket_authorized">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns <code>true</code> if the peer certificate was signed by one of the CAs specified
when creating the <code>tls.TLSSocket</code> instance, otherwise <code>false</code>.</p>
<h3>tlsSocket.disableRenegotiation()<span><a class="mark" href="#tls_tlssocket_disablerenegotiation" id="tls_tlssocket_disablerenegotiation">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v8.4.0</span>
</div><p>Disables TLS renegotiation for this <code>TLSSocket</code> instance. Once called, attempts
to renegotiate will trigger an <code>&apos;error&apos;</code> event on the <code>TLSSocket</code>.</p>
<h3>tlsSocket.encrypted<span><a class="mark" href="#tls_tlssocket_encrypted" id="tls_tlssocket_encrypted">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Always returns <code>true</code>. This may be used to distinguish TLS sockets from regular
<code>net.Socket</code> instances.</p>
<h3>tlsSocket.getCipher()<span><a class="mark" href="#tls_tlssocket_getcipher" id="tls_tlssocket_getcipher">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns an object representing the cipher name. The <code>version</code> key is a legacy
field which always contains the value <code>&apos;TLSv1/SSLv3&apos;</code>.</p>
<p>For example: <code>{ name: &apos;AES256-SHA&apos;, version: &apos;TLSv1/SSLv3&apos; }</code></p>
<p>See <code>SSL_CIPHER_get_name()</code> in
<a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CIPHER_get_name.html">https://www.openssl.org/docs/man1.0.2/ssl/SSL_CIPHER_get_name.html</a> for more
information.</p>
<h3>tlsSocket.getEphemeralKeyInfo()<span><a class="mark" href="#tls_tlssocket_getephemeralkeyinfo" id="tls_tlssocket_getephemeralkeyinfo">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v5.0.0</span>
</div><p>Returns an object representing the type, name, and size of parameter of
an ephemeral key exchange in [Perfect Forward Secrecy][] on a client
connection. It returns an empty object when the key exchange is not
ephemeral. As this is only supported on a client socket; <code>null</code> is returned
if called on a server socket. The supported types are <code>&apos;DH&apos;</code> and <code>&apos;ECDH&apos;</code>. The
<code>name</code> property is available only when type is &apos;ECDH&apos;.</p>
<p>For Example: <code>{ type: &apos;ECDH&apos;, name: &apos;prime256v1&apos;, size: 256 }</code></p>
<h3>tlsSocket.getPeerCertificate([detailed])<span><a class="mark" href="#tls_tlssocket_getpeercertificate_detailed" id="tls_tlssocket_getpeercertificate_detailed">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><ul>
<li><code>detailed</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Include the full certificate chain if <code>true</code>, otherwise
include just the peer&apos;s certificate.</li>
</ul>
<p>Returns an object representing the peer&apos;s certificate. The returned object has
some properties corresponding to the fields of the certificate.</p>
<p>If the full certificate chain was requested, each certificate will include a
<code>issuerCertificate</code> property containing an object representing its issuer&apos;s
certificate.</p>
<p>For example:</p>
<pre><code class="lang-text">{ subject:
   { C: &apos;UK&apos;,
     ST: &apos;Acknack Ltd&apos;,
     L: &apos;Rhys Jones&apos;,
     O: &apos;node.js&apos;,
     OU: &apos;Test TLS Certificate&apos;,
     CN: &apos;localhost&apos; },
  issuer:
   { C: &apos;UK&apos;,
     ST: &apos;Acknack Ltd&apos;,
     L: &apos;Rhys Jones&apos;,
     O: &apos;node.js&apos;,
     OU: &apos;Test TLS Certificate&apos;,
     CN: &apos;localhost&apos; },
  issuerCertificate:
   { ... another certificate, possibly with a .issuerCertificate ... },
  raw: &lt; RAW DER buffer &gt;,
  valid_from: &apos;Nov 11 09:52:22 2009 GMT&apos;,
  valid_to: &apos;Nov  6 09:52:22 2029 GMT&apos;,
  fingerprint: &apos;2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF&apos;,
  serialNumber: &apos;B9B0D332A1AA5635&apos; }
</code></pre>
<p>If the peer does not provide a certificate, an empty object will be returned.</p>
<h3>tlsSocket.getProtocol()<span><a class="mark" href="#tls_tlssocket_getprotocol" id="tls_tlssocket_getprotocol">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v5.7.0</span>
</div><p>Returns a string containing the negotiated SSL/TLS protocol version of the
current connection. The value <code>&apos;unknown&apos;</code> will be returned for connected
sockets that have not completed the handshaking process. The value <code>null</code> will
be returned for server sockets or disconnected client sockets.</p>
<p>Example responses include:</p>
<ul>
<li><code>SSLv3</code></li>
<li><code>TLSv1</code></li>
<li><code>TLSv1.1</code></li>
<li><code>TLSv1.2</code></li>
<li><code>unknown</code></li>
</ul>
<p>See <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_get_version.html">https://www.openssl.org/docs/man1.0.2/ssl/SSL_get_version.html</a> for more
information.</p>
<h3>tlsSocket.getSession()<span><a class="mark" href="#tls_tlssocket_getsession" id="tls_tlssocket_getsession">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the ASN.1 encoded TLS session or <code>undefined</code> if no session was
negotiated. Can be used to speed up handshake establishment when reconnecting
to the server.</p>
<h3>tlsSocket.getTLSTicket()<span><a class="mark" href="#tls_tlssocket_gettlsticket" id="tls_tlssocket_gettlsticket">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the TLS session ticket or <code>undefined</code> if no session was negotiated.</p>
<p><em>Note</em>: This only works with client TLS sockets. Useful only for debugging,
for session reuse provide <code>session</code> option to [<code>tls.connect()</code>][].</p>
<h3>tlsSocket.localAddress<span><a class="mark" href="#tls_tlssocket_localaddress" id="tls_tlssocket_localaddress">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the string representation of the local IP address.</p>
<h3>tlsSocket.localPort<span><a class="mark" href="#tls_tlssocket_localport" id="tls_tlssocket_localport">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the numeric representation of the local port.</p>
<h3>tlsSocket.remoteAddress<span><a class="mark" href="#tls_tlssocket_remoteaddress" id="tls_tlssocket_remoteaddress">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the string representation of the remote IP address. For example,
<code>&apos;74.125.127.100&apos;</code> or <code>&apos;2001:4860:a005::68&apos;</code>.</p>
<h3>tlsSocket.remoteFamily<span><a class="mark" href="#tls_tlssocket_remotefamily" id="tls_tlssocket_remotefamily">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the string representation of the remote IP family. <code>&apos;IPv4&apos;</code> or <code>&apos;IPv6&apos;</code>.</p>
<h3>tlsSocket.remotePort<span><a class="mark" href="#tls_tlssocket_remoteport" id="tls_tlssocket_remoteport">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.4</span>
</div><p>Returns the numeric representation of the remote port. For example, <code>443</code>.</p>
<h3>tlsSocket.renegotiate(options, callback)<span><a class="mark" href="#tls_tlssocket_renegotiate_options_callback" id="tls_tlssocket_renegotiate_options_callback">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.8</span>
</div><ul>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>rejectUnauthorized</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If not <code>false</code>, the server certificate is verified
against the list of supplied CAs. An <code>&apos;error&apos;</code> event is emitted if
verification fails; <code>err.code</code> contains the OpenSSL error code. Defaults to
<code>true</code>.</li>
<li><code>requestCert</code></li>
</ul>
</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A function that will be called when the renegotiation
request has been completed.</li>
</ul>
<p>The <code>tlsSocket.renegotiate()</code> method initiates a TLS renegotiation process.
Upon completion, the <code>callback</code> function will be passed a single argument
that is either an <code>Error</code> (if the request failed) or <code>null</code>.</p>
<p><em>Note</em>: This method can be used to request a peer&apos;s certificate after the
secure connection has been established.</p>
<p><em>Note</em>: When running as the server, the socket will be destroyed with an error
after <code>handshakeTimeout</code> timeout.</p>
<h3>tlsSocket.setMaxSendFragment(size)<span><a class="mark" href="#tls_tlssocket_setmaxsendfragment_size" id="tls_tlssocket_setmaxsendfragment_size">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.11</span>
</div><ul>
<li><code>size</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> The maximum TLS fragment size. Defaults to <code>16384</code>. The
maximum value is <code>16384</code>.</li>
</ul>
<p>The <code>tlsSocket.setMaxSendFragment()</code> method sets the maximum TLS fragment size.
Returns <code>true</code> if setting the limit succeeded; <code>false</code> otherwise.</p>
<p>Smaller fragment sizes decrease the buffering latency on the client: larger
fragments are buffered by the TLS layer until the entire fragment is received
and its integrity is verified; large fragments can span multiple roundtrips
and their processing can be delayed due to packet loss or reordering. However,
smaller fragments add extra TLS framing bytes and CPU overhead, which may
decrease overall server throughput.</p>
<h2>tls.checkServerIdentity(host, cert)<span><a class="mark" href="#tls_tls_checkserveridentity_host_cert" id="tls_tls_checkserveridentity_host_cert">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.8.4</span>
</div><ul>
<li><code>host</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The hostname to verify the certificate against</li>
<li><code>cert</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> An object representing the peer&apos;s certificate. The returned
object has some properties corresponding to the fields of the certificate.</li>
</ul>
<p>Verifies the certificate <code>cert</code> is issued to host <code>host</code>.</p>
<p>Returns 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a> object, populating it with the reason, host, and cert on
failure. On success, returns 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type">&lt;undefined&gt;</a>.</p>
<p><em>Note</em>: This function can be overwritten by providing alternative function
as part of the <code>options.checkServerIdentity</code> option passed to <code>tls.connect()</code>.
The overwriting function can call <code>tls.checkServerIdentity()</code> of course, to augment
the checks done with additional verification.</p>
<p><em>Note</em>: This function is only called if the certificate passed all other checks, such as
being issued by trusted CA (<code>options.ca</code>).</p>
<p>The cert object contains the parsed certificate and will have a structure similar to:</p>
<pre><code class="lang-text">{ subject:
   { OU: [ &apos;Domain Control Validated&apos;, &apos;PositiveSSL Wildcard&apos; ],
     CN: &apos;*.nodejs.org&apos; },
  issuer:
   { C: &apos;GB&apos;,
     ST: &apos;Greater Manchester&apos;,
     L: &apos;Salford&apos;,
     O: &apos;COMODO CA Limited&apos;,
     CN: &apos;COMODO RSA Domain Validation Secure Server CA&apos; },
  subjectaltname: &apos;DNS:*.nodejs.org, DNS:nodejs.org&apos;,
  infoAccess:
   { &apos;CA Issuers - URI&apos;:
      [ &apos;http://crt.comodoca.com/COMODORSADomainValidationSecureServerCA.crt&apos; ],
     &apos;OCSP - URI&apos;: [ &apos;http://ocsp.comodoca.com&apos; ] },
  modulus: &apos;B56CE45CB740B09A13F64AC543B712FF9EE8E4C284B542A1708A27E82A8D151CA178153E12E6DDA15BF70FFD96CB8A88618641BDFCCA03527E665B70D779C8A349A6F88FD4EF6557180BD4C98192872BCFE3AF56E863C09DDD8BC1EC58DF9D94F914F0369102B2870BECFA1348A0838C9C49BD1C20124B442477572347047506B1FCD658A80D0C44BCC16BC5C5496CFE6E4A8428EF654CD3D8972BF6E5BFAD59C93006830B5EB1056BBB38B53D1464FA6E02BFDF2FF66CD949486F0775EC43034EC2602AEFBF1703AD221DAA2A88353C3B6A688EFE8387811F645CEED7B3FE46E1F8B9F59FAD028F349B9BC14211D5830994D055EEA3D547911E07A0ADDEB8A82B9188E58720D95CD478EEC9AF1F17BE8141BE80906F1A339445A7EB5B285F68039B0F294598A7D1C0005FC22B5271B0752F58CCDEF8C8FD856FB7AE21C80B8A2CE983AE94046E53EDE4CB89F42502D31B5360771C01C80155918637490550E3F555E2EE75CC8C636DDE3633CFEDD62E91BF0F7688273694EEEBA20C2FC9F14A2A435517BC1D7373922463409AB603295CEB0BB53787A334C9CA3CA8B30005C5A62FC0715083462E00719A8FA3ED0A9828C3871360A73F8B04A4FC1E71302844E9BB9940B77E745C9D91F226D71AFCAD4B113AAF68D92B24DDB4A2136B55A1CD1ADF39605B63CB639038ED0F4C987689866743A68769CC55847E4A06D6E2E3F1&apos;,
  exponent: &apos;0x10001&apos;,
  valid_from: &apos;Aug 14 00:00:00 2017 GMT&apos;,
  valid_to: &apos;Nov 20 23:59:59 2019 GMT&apos;,
  fingerprint: &apos;01:02:59:D9:C3:D2:0D:08:F7:82:4E:44:A4:B4:53:C5:E2:3A:87:4D&apos;,
  ext_key_usage: [ &apos;1.3.6.1.5.5.7.3.1&apos;, &apos;1.3.6.1.5.5.7.3.2&apos; ],
  serialNumber: &apos;66593D57F20CBC573E433381B5FEC280&apos;,
  raw: &lt;Buffer ....&gt; }
</code></pre>
<h2>tls.connect(options[, callback])<span><a class="mark" href="#tls_tls_connect_options_callback" id="tls_tls_connect_options_callback">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>lookup</code> option is supported now.</p>
</td></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>ALPNProtocols</code> and <code>NPNProtocols</code> options can be <code>Uint8Array</code>s now.</p>
</td></tr>
<tr><td>v5.3.0, v4.7.0</td>
<td><p>The <code>secureContext</code> option is supported now.</p>
</td></tr>
<tr><td>v5.0.0</td>
<td><p>ALPN options are supported now.</p>
</td></tr>
<tr><td>v0.11.3</td>
<td><p><span>新增于: v0.11.3</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>host</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Host the client should connect to, defaults to &apos;localhost&apos;.</li>
<li><code>port</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Port the client should connect to.</li>
<li><code>path</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Creates unix socket connection to path. If this option is
specified, <code>host</code> and <code>port</code> are ignored.</li>
<li><code>socket</code> 
            <a href="stream.html#stream_class_stream_duplex" class="type">&lt;stream.Duplex&gt;</a> Establish secure connection on a given socket
rather than creating a new socket. Typically, this is an instance of
[<code>net.Socket</code>][], but any <code>Duplex</code> stream is allowed.
If this option is specified, <code>path</code>, <code>host</code> and <code>port</code> are ignored,
except for certificate validation.  Usually, a socket is already connected
when passed to <code>tls.connect()</code>, but it can be connected later. Note that
connection/disconnection/destruction of <code>socket</code> is the user&apos;s
responsibility, calling <code>tls.connect()</code> will not cause <code>net.connect()</code> to be
called.</li>
<li><code>rejectUnauthorized</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If not <code>false</code>, the server certificate is verified
against the list of supplied CAs. An <code>&apos;error&apos;</code> event is emitted if
verification fails; <code>err.code</code> contains the OpenSSL error code. Defaults to
<code>true</code>.</li>
<li><code>NPNProtocols</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a>
An array of strings, <code>Buffer</code>s or <code>Uint8Array</code>s, or a single <code>Buffer</code> or
<code>Uint8Array</code> containing supported NPN protocols. <code>Buffer</code>s should have the
format <code>[len][name][len][name]...</code> e.g. <code>0x05hello0x05world</code>, where the
first byte is the length of the next protocol name. Passing an array is
usually much simpler, e.g. <code>[&apos;hello&apos;, &apos;world&apos;]</code>.</li>
<li><code>ALPNProtocols</code>: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a>
An array of strings, <code>Buffer</code>s or <code>Uint8Array</code>s, or a single <code>Buffer</code> or
<code>Uint8Array</code> containing the supported ALPN protocols. <code>Buffer</code>s should have
the format <code>[len][name][len][name]...</code> e.g. <code>0x05hello0x05world</code>, where the
first byte is the length of the next protocol name. Passing an array is
usually much simpler, e.g. <code>[&apos;hello&apos;, &apos;world&apos;]</code>.</li>
<li><code>servername</code>: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Server name for the SNI (Server Name Indication) TLS
extension.</li>
<li><code>checkServerIdentity(servername, cert)</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A callback function
to be used (instead of the builtin <code>tls.checkServerIdentity()</code> function)
when checking the server&apos;s hostname (or the provided <code>servername</code> when
explicitly set) against the certificate. This should return an 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&lt;Error&gt;</a> if
verification fails. The method should return <code>undefined</code> if the <code>servername</code>
and <code>cert</code> are verified.</li>
<li><code>session</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> A <code>Buffer</code> instance, containing TLS session.</li>
<li><code>minDHSize</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Minimum size of the DH parameter in bits to accept a
TLS connection. When a server offers a DH parameter with a size less
than <code>minDHSize</code>, the TLS connection is destroyed and an error is thrown.
Defaults to <code>1024</code>.</li>
<li><code>secureContext</code>: Optional TLS context object created with
[<code>tls.createSecureContext()</code>][]. If a <code>secureContext</code> is <em>not</em> provided, one
will be created by passing the entire <code>options</code> object to
<code>tls.createSecureContext()</code>.</li>
<li><code>lookup</code>: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> Custom lookup function. Defaults to [<code>dns.lookup()</code>][].</li>
<li>...: Optional [<code>tls.createSecureContext()</code>][] options that are used if the
<code>secureContext</code> option is missing, otherwise they are ignored.</li>
</ul>
</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>The <code>callback</code> function, if specified, will be added as a listener for the
[<code>&apos;secureConnect&apos;</code>][] event.</p>
<p><code>tls.connect()</code> returns a [<code>tls.TLSSocket</code>][] object.</p>
<p>The following implements a simple &quot;echo server&quot; example:</p>
<pre><code class="lang-js">const tls = require(&apos;tls&apos;);
const fs = require(&apos;fs&apos;);

const options = {
  // Necessary only if using the client certificate authentication
  key: fs.readFileSync(&apos;client-key.pem&apos;),
  cert: fs.readFileSync(&apos;client-cert.pem&apos;),

  // Necessary only if the server uses the self-signed certificate
  ca: [ fs.readFileSync(&apos;server-cert.pem&apos;) ]
};

const socket = tls.connect(8000, options, () =&gt; {
  console.log(&apos;client connected&apos;,
              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);
  process.stdin.pipe(socket);
  process.stdin.resume();
});
socket.setEncoding(&apos;utf8&apos;);
socket.on(&apos;data&apos;, (data) =&gt; {
  console.log(data);
});
socket.on(&apos;end&apos;, () =&gt; {
  server.close();
});
</code></pre>
<p>Or</p>
<pre><code class="lang-js">const tls = require(&apos;tls&apos;);
const fs = require(&apos;fs&apos;);

const options = {
  pfx: fs.readFileSync(&apos;client.pfx&apos;)
};

const socket = tls.connect(8000, options, () =&gt; {
  console.log(&apos;client connected&apos;,
              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);
  process.stdin.pipe(socket);
  process.stdin.resume();
});
socket.setEncoding(&apos;utf8&apos;);
socket.on(&apos;data&apos;, (data) =&gt; {
  console.log(data);
});
socket.on(&apos;end&apos;, () =&gt; {
  server.close();
});
</code></pre>
<h2>tls.connect(path[, options][, callback])<span><a class="mark" href="#tls_tls_connect_path_options_callback" id="tls_tls_connect_path_options_callback">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.11.3</span>
</div><ul>
<li><code>path</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Default value for <code>options.path</code>.</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> See [<code>tls.connect()</code>][].</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> See [<code>tls.connect()</code>][].</li>
</ul>
<p>Same as [<code>tls.connect()</code>][] except that <code>path</code> can be provided
as an argument instead of an option.</p>
<p><em>Note</em>: A path option, if specified, will take precedence over the path
argument.</p>
<h2>tls.connect(port[, host][, options][, callback])<span><a class="mark" href="#tls_tls_connect_port_host_options_callback" id="tls_tls_connect_port_host_options_callback">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.11.3</span>
</div><ul>
<li><code>port</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Default value for <code>options.port</code>.</li>
<li><code>host</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Optional default value for <code>options.host</code>.</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> See [<code>tls.connect()</code>][].</li>
<li><code>callback</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> See [<code>tls.connect()</code>][].</li>
</ul>
<p>Same as [<code>tls.connect()</code>][] except that <code>port</code> and <code>host</code> can be provided
as arguments instead of options.</p>
<p><em>Note</em>: A port or host option, if specified, will take precedence over any
port or host argument.</p>
<h2>tls.createSecureContext(options)<span><a class="mark" href="#tls_tls_createsecurecontext_options" id="tls_tls_createsecurecontext_options">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v7.3.0</td>
<td><p>If the <code>key</code> option is an array, individual entries do not need a <code>passphrase</code> property anymore. Array entries can also just be <code>string</code>s or <code>Buffer</code>s now.</p>
</td></tr>
<tr><td>v5.2.0</td>
<td><p>The <code>ca</code> option can now be a single string containing multiple CA certificates.</p>
</td></tr>
<tr><td>v0.11.13</td>
<td><p><span>新增于: v0.11.13</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>pfx</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a> Optional PFX or PKCS12
encoded private key and certificate chain. <code>pfx</code> is an alternative to
providing <code>key</code> and <code>cert</code> individually. PFX is usually encrypted, if it is,
<code>passphrase</code> will be used to decrypt it. Multiple PFX can be provided either
as an array of unencrypted PFX buffers, or an array of objects in the form
<code>{buf: &lt;string|buffer&gt;[, passphrase: &lt;string&gt;]}</code>. The object form can only
occur in an array. <code>object.passphrase</code> is optional. Encrypted PFX will be
decrypted with <code>object.passphrase</code> if provided, or <code>options.passphrase</code> if it is not.</li>
<li><code>key</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object[]&gt;</a> Optional private keys in
PEM format. PEM allows the option of private keys being encrypted. Encrypted
keys will be decrypted with <code>options.passphrase</code>.  Multiple keys using
different algorithms can be provided either as an array of unencrypted key
strings or buffers, or an array of objects in the form <code>{pem:
&lt;string|buffer&gt;[, passphrase: &lt;string&gt;]}</code>. The object form can only occur in
an array. <code>object.passphrase</code> is optional. Encrypted keys will be decrypted
with <code>object.passphrase</code> if provided, or <code>options.passphrase</code> if it is not.</li>
<li><code>passphrase</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Optional shared passphrase used for a single private
key and/or a PFX.</li>
<li><code>cert</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> Optional cert chains in PEM format.
One cert chain should be provided per private key. Each cert chain should
consist of the PEM formatted certificate for a provided private <code>key</code>,
followed by the PEM formatted intermediate certificates (if any), in order,
and not including the root CA (the root CA must be pre-known to the peer,
see <code>ca</code>).  When providing multiple cert chains, they do not have to be in
the same order as their private keys in <code>key</code>. If the intermediate
certificates are not provided, the peer will not be able to validate the
certificate, and the handshake will fail.</li>
<li><code>ca</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> Optionally override the trusted CA
certificates. Default is to trust the well-known CAs curated by Mozilla.
Mozilla&apos;s CAs are completely replaced when CAs are explicitly specified
using this option. The value can be a string or Buffer, or an Array of
strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs
concatenated together. The peer&apos;s certificate must be chainable to a CA
trusted by the server for the connection to be authenticated.  When using
certificates that are not chainable to a well-known CA, the certificate&apos;s CA
must be explicitly specified as a trusted or the connection will fail to
authenticate.
If the peer uses a certificate that doesn&apos;t match or chain to one of the
default CAs, use the <code>ca</code> option to provide a CA certificate that the peer&apos;s
certificate can match or chain to.
For self-signed certificates, the certificate is its own CA, and must be
provided.</li>
<li><code>crl</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> Optional PEM formatted
CRLs (Certificate Revocation Lists).</li>
<li><code>ciphers</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Optional cipher suite specification, replacing the
default.  For more information, see [modifying the default cipher suite][].</li>
<li><code>honorCipherOrder</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> Attempt to use the server&apos;s cipher suite
preferences instead of the client&apos;s. When <code>true</code>, causes
<code>SSL_OP_CIPHER_SERVER_PREFERENCE</code> to be set in <code>secureOptions</code>, see
[OpenSSL Options][] for more information.</li>
<li><code>ecdhCurve</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> A string describing a named curve or a colon separated
list of curve NIDs or names, for example <code>P-521:P-384:P-256</code>, to use for
ECDH key agreement, or <code>false</code> to disable ECDH. Set to <code>auto</code> to select the
curve automatically. Defaults to [<code>tls.DEFAULT_ECDH_CURVE</code>]. Use
[<code>crypto.getCurves()</code>][] to obtain a list of available curve names. On
recent releases, <code>openssl ecparam -list_curves</code> will also display the name
and description of each available elliptic curve.</li>
<li><code>dhparam</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> Diffie Hellman parameters, required for
[Perfect Forward Secrecy][]. Use <code>openssl dhparam</code> to create the parameters.
The key length must be greater than or equal to 1024 bits, otherwise an
error will be thrown. It is strongly recommended to use 2048 bits or larger
for stronger security. If omitted or invalid, the parameters are silently
discarded and DHE ciphers will not be available.</li>
<li><code>secureProtocol</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Optional SSL method to use, default is
<code>&quot;SSLv23_method&quot;</code>. The possible values are listed as [SSL_METHODS][], use
the function names as strings. For example, <code>&quot;SSLv3_method&quot;</code> to force SSL
version 3.</li>
<li><code>secureOptions</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Optionally affect the OpenSSL protocol behavior,
which is not usually necessary. This should be used carefully if at all!
Value is a numeric bitmask of the <code>SSL_OP_*</code> options from
[OpenSSL Options][].</li>
<li><code>sessionIdContext</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Optional opaque identifier used by servers to
ensure session state is not shared between applications. Unused by clients.</li>
</ul>
</li>
</ul>
<p><em>Note</em>:</p>
<ul>
<li><p>[<code>tls.createServer()</code>][] sets the default value of the
<code>honorCipherOrder</code> option to <code>true</code>, other APIs that create secure contexts
leave it unset.</p>
</li>
<li><p>[<code>tls.createServer()</code>][] uses a 128 bit truncated SHA1 hash value
generated from <code>process.argv</code> as the default value of the <code>sessionIdContext</code>
option, other APIs that create secure contexts have no default value.</p>
</li>
</ul>
<p>The <code>tls.createSecureContext()</code> method creates a credentials object.</p>
<p>A key is <em>required</em> for ciphers that make use of certificates. Either <code>key</code> or
<code>pfx</code> can be used to provide it.</p>
<p>If the &apos;ca&apos; option is not given, then Node.js will use the default
publicly trusted list of CAs as given in
<a href="https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt">https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt</a>.</p>
<h2>tls.createServer([options][, secureConnectionListener])<span><a class="mark" href="#tls_tls_createserver_options_secureconnectionlistener" id="tls_tls_createserver_options_secureconnectionlistener">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v8.0.0</td>
<td><p>The <code>ALPNProtocols</code> and <code>NPNProtocols</code> options can be <code>Uint8Array</code>s now.</p>
</td></tr>
<tr><td>v5.0.0</td>
<td><p>ALPN options are supported now.</p>
</td></tr>
<tr><td>v0.3.2</td>
<td><p><span>新增于: v0.3.2</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>handshakeTimeout</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Abort the connection if the SSL/TLS handshake
does not finish in the specified number of milliseconds. Defaults to <code>120</code>
seconds. A <code>&apos;tlsClientError&apos;</code> is emitted on the <code>tls.Server</code> object whenever
a handshake times out.</li>
<li><code>requestCert</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code> the server will request a certificate from
clients that connect and attempt to verify that certificate. Defaults to
<code>false</code>.</li>
<li><code>rejectUnauthorized</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If not <code>false</code> the server will reject any
connection which is not authorized with the list of supplied CAs. This
option only has an effect if <code>requestCert</code> is <code>true</code>. Defaults to <code>true</code>.</li>
<li><code>NPNProtocols</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a>
An array of strings, <code>Buffer</code>s or <code>Uint8Array</code>s, or a single <code>Buffer</code> or
<code>Uint8Array</code> containing supported NPN protocols. <code>Buffer</code>s should have the
format <code>[len][name][len][name]...</code> e.g. <code>0x05hello0x05world</code>, where the
first byte is the length of the next protocol name. Passing an array is
usually much simpler, e.g. <code>[&apos;hello&apos;, &apos;world&apos;]</code>.
(Protocols should be ordered by their priority.)</li>
<li><code>ALPNProtocols</code>: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer[]&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array[]&gt;</a> | 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a>
An array of strings, <code>Buffer</code>s or <code>Uint8Array</code>s, or a single <code>Buffer</code> or
<code>Uint8Array</code> containing the supported ALPN protocols. <code>Buffer</code>s should have
the format <code>[len][name][len][name]...</code> e.g. <code>0x05hello0x05world</code>, where the
first byte is the length of the next protocol name. Passing an array is
usually much simpler, e.g. <code>[&apos;hello&apos;, &apos;world&apos;]</code>.
(Protocols should be ordered by their priority.)
When the server receives both NPN and ALPN extensions from the client,
ALPN takes precedence over NPN and the server does not send an NPN
extension to the client.</li>
<li><code>SNICallback(servername, cb)</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A function that will be called if
the client supports SNI TLS extension. Two arguments will be passed when
called: <code>servername</code> and <code>cb</code>. <code>SNICallback</code> should invoke <code>cb(null, ctx)</code>,
where <code>ctx</code> is a SecureContext instance. (<code>tls.createSecureContext(...)</code> can
be used to get a proper SecureContext.) If <code>SNICallback</code> wasn&apos;t provided the
default callback with high-level API will be used (see below).</li>
<li><code>sessionTimeout</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> An integer specifying the number of seconds after
which the TLS session identifiers and TLS session tickets created by the
server will time out. See [SSL_CTX_set_timeout] for more details.</li>
<li><code>ticketKeys</code>: A 48-byte <code>Buffer</code> instance consisting of a 16-byte prefix,
a 16-byte HMAC key, and a 16-byte AES key. This can be used to accept TLS
session tickets on multiple instances of the TLS server.</li>
<li>...: Any [<code>tls.createSecureContext()</code>][] options can be provided. For
servers, the identity options (<code>pfx</code> or <code>key</code>/<code>cert</code>) are usually required.</li>
</ul>
</li>
<li><code>secureConnectionListener</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Creates a new [tls.Server][].  The <code>secureConnectionListener</code>, if provided, is
automatically set as a listener for the [<code>&apos;secureConnection&apos;</code>][] event.</p>
<p><em>Note</em>: The <code>ticketKeys</code> options is automatically shared between <code>cluster</code>
module workers.</p>
<p>The following illustrates a simple echo server:</p>
<pre><code class="lang-js">const tls = require(&apos;tls&apos;);
const fs = require(&apos;fs&apos;);

const options = {
  key: fs.readFileSync(&apos;server-key.pem&apos;),
  cert: fs.readFileSync(&apos;server-cert.pem&apos;),

  // This is necessary only if using the client certificate authentication.
  requestCert: true,

  // This is necessary only if the client uses the self-signed certificate.
  ca: [ fs.readFileSync(&apos;client-cert.pem&apos;) ]
};

const server = tls.createServer(options, (socket) =&gt; {
  console.log(&apos;server connected&apos;,
              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);
  socket.write(&apos;welcome!\n&apos;);
  socket.setEncoding(&apos;utf8&apos;);
  socket.pipe(socket);
});
server.listen(8000, () =&gt; {
  console.log(&apos;server bound&apos;);
});
</code></pre>
<p>Or</p>
<pre><code class="lang-js">const tls = require(&apos;tls&apos;);
const fs = require(&apos;fs&apos;);

const options = {
  pfx: fs.readFileSync(&apos;server.pfx&apos;),

  // This is necessary only if using the client certificate authentication.
  requestCert: true,

};

const server = tls.createServer(options, (socket) =&gt; {
  console.log(&apos;server connected&apos;,
              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);
  socket.write(&apos;welcome!\n&apos;);
  socket.setEncoding(&apos;utf8&apos;);
  socket.pipe(socket);
});
server.listen(8000, () =&gt; {
  console.log(&apos;server bound&apos;);
});
</code></pre>
<p>This server can be tested by connecting to it using <code>openssl s_client</code>:</p>
<pre><code class="lang-sh">openssl s_client -connect 127.0.0.1:8000
</code></pre>
<h2>tls.getCiphers()<span><a class="mark" href="#tls_tls_getciphers" id="tls_tls_getciphers">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.10.2</span>
</div><p>Returns an array with the names of the supported SSL ciphers.</p>
<p>For example:</p>
<pre><code class="lang-js">console.log(tls.getCiphers()); // [&apos;AES128-SHA&apos;, &apos;AES256-SHA&apos;, ...]
</code></pre>
<h2>tls.DEFAULT_ECDH_CURVE<span><a class="mark" href="#tls_tls_default_ecdh_curve" id="tls_tls_default_ecdh_curve">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.11.13</span>
</div><p>The default curve name to use for ECDH key agreement in a tls server. The
default value is <code>&apos;prime256v1&apos;</code> (NIST P-256). Consult [RFC 4492] and
[FIPS.186-4] for more details.</p>
<h2>Deprecated APIs<span><a class="mark" href="#tls_deprecated_apis" id="tls_deprecated_apis">#</a></span></h2>
<h3>Class: CryptoStream<span><a class="mark" href="#tls_class_cryptostream" id="tls_class_cryptostream">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.4</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use [<code>tls.TLSSocket</code>][] instead.</div><p>The <code>tls.CryptoStream</code> class represents a stream of encrypted data. This class
has been deprecated and should no longer be used.</p>
<h4>cryptoStream.bytesWritten<span><a class="mark" href="#tls_cryptostream_byteswritten" id="tls_cryptostream_byteswritten">#</a></span></h4>
<div class="api_metadata">
<span>新增于: v0.3.4</span><span>废弃于: v0.11.3</span>
</div><p>The <code>cryptoStream.bytesWritten</code> property returns the total number of bytes
written to the underlying socket <em>including</em> the bytes required for the
implementation of the TLS protocol.</p>
<h3>Class: SecurePair<span><a class="mark" href="#tls_class_securepair" id="tls_class_securepair">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.2</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use [<code>tls.TLSSocket</code>][] instead.</div><p>Returned by [<code>tls.createSecurePair()</code>][].</p>
<h4>Event: &apos;secure&apos;<span><a class="mark" href="#tls_event_secure" id="tls_event_secure">#</a></span></h4>
<div class="api_metadata">
<span>新增于: v0.3.2</span><span>废弃于: v0.11.3</span>
</div><p>The <code>&apos;secure&apos;</code> event is emitted by the <code>SecurePair</code> object once a secure
connection has been established.</p>
<p>As with checking for the server <a href="#tls_event_secureconnection"><code>secureConnection</code></a>
event, <code>pair.cleartext.authorized</code> should be inspected to confirm whether the
certificate used is properly authorized.</p>
<h3>tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])<span><a class="mark" href="#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options" id="tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options">#</a></span></h3>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v5.0.0</td>
<td><p>ALPN options are supported now.</p>
</td></tr>
<tr><td>v0.11.3</td>
<td><p><span>废弃于: v0.11.3</span></p>
</td></tr>
<tr><td>v0.3.2</td>
<td><p><span>新增于: v0.3.2</span></p>
</td></tr>
</tbody></table>
</details>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use [<code>tls.TLSSocket</code>][] instead.</div><ul>
<li><code>context</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> A secure context object as returned by
<code>tls.createSecureContext()</code></li>
<li><code>isServer</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> to specify that this TLS connection should be
opened as a server.</li>
<li><code>requestCert</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> to specify whether a server should request a
certificate from a connecting client. Only applies when <code>isServer</code> is <code>true</code>.</li>
<li><code>rejectUnauthorized</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If not <code>false</code> a server automatically reject clients
 with invalid certificates. Only applies when <code>isServer</code> is <code>true</code>.</li>
<li><code>options</code><ul>
<li><code>secureContext</code>: An optional TLS context object from
 [<code>tls.createSecureContext()</code>][]</li>
<li><code>isServer</code>: If <code>true</code> the TLS socket will be instantiated in server-mode.
Defaults to <code>false</code>.</li>
<li><code>server</code> <span class="type">&lt;net.Server&gt;</span> An optional [<code>net.Server</code>][] instance</li>
<li><code>requestCert</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>rejectUnauthorized</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>NPNProtocols</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>ALPNProtocols</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>SNICallback</code>: Optional, see [<code>tls.createServer()</code>][]</li>
<li><code>session</code> 
            <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> An optional <code>Buffer</code> instance containing a TLS session.</li>
<li><code>requestOCSP</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> If <code>true</code>, specifies that the OCSP status request
extension will be added to the client hello and an <code>&apos;OCSPResponse&apos;</code> event
will be emitted on the socket before establishing a secure communication</li>
</ul>
</li>
</ul>
<p>Creates a new secure pair object with two streams, one of which reads and writes
the encrypted data and the other of which reads and writes the cleartext data.
Generally, the encrypted stream is piped to/from an incoming encrypted data
stream and the cleartext one is used as a replacement for the initial encrypted
stream.</p>
<p><code>tls.createSecurePair()</code> returns a <code>tls.SecurePair</code> object with <code>cleartext</code> and
<code>encrypted</code> stream properties.</p>
<p><em>Note</em>: <code>cleartext</code> has the same API as [<code>tls.TLSSocket</code>][].</p>
<p><em>Note</em>: The <code>tls.createSecurePair()</code> method is now deprecated in favor of
<code>tls.TLSSocket()</code>. For example, the code:</p>
<pre><code class="lang-js">pair = tls.createSecurePair(/* ... */);
pair.encrypted.pipe(socket);
socket.pipe(pair.encrypted);
</code></pre>
<p>can be replaced by:</p>
<pre><code class="lang-js">secure_socket = tls.TLSSocket(socket, options);
</code></pre>
<p>where <code>secure_socket</code> has the same API as <code>pair.cleartext</code>.
[<code>&apos;secureConnect&apos;</code>]: #tls_event_secureconnect
[<code>&apos;secureConnection&apos;</code>]: #tls_event_secureconnection
[<code>crypto.getCurves()</code>]: crypto.html#crypto_crypto_getcurves
[<code>net.Server.address()</code>]: net.html#net_server_address
[<code>net.Server</code>]: net.html#net_class_net_server
[<code>net.Socket</code>]: net.html#net_class_net_socket
[<code>server.getConnections()</code>]: net.html#net_server_getconnections_callback
[<code>server.listen()</code>]: net.html#net_server_listen
[<code>tls.DEFAULT_ECDH_CURVE</code>]: #tls_tls_default_ecdh_curve
[<code>tls.TLSSocket.getPeerCertificate()</code>]: #tls_tlssocket_getpeercertificate_detailed
[<code>tls.TLSSocket</code>]: #tls_class_tls_tlssocket
[<code>tls.connect()</code>]: #tls_tls_connect_options_callback
[<code>tls.createSecureContext()</code>]: #tls_tls_createsecurecontext_options
[<code>tls.createSecurePair()</code>]: #tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options
[<code>tls.createServer()</code>]: #tls_tls_createserver_options_secureconnectionlistener
[Chrome&apos;s &apos;modern cryptography&apos; setting]: <a href="https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites">https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites</a>
[DHE]: <a href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange</a>
[ECDHE]: <a href="https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman">https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman</a>
[FIPS.186-4]: <a href="http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf">http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf</a>
[Forward secrecy]: <a href="https://en.wikipedia.org/wiki/Perfect_forward_secrecy">https://en.wikipedia.org/wiki/Perfect_forward_secrecy</a>
[OCSP request]: <a href="https://en.wikipedia.org/wiki/OCSP_stapling">https://en.wikipedia.org/wiki/OCSP_stapling</a>
[OpenSSL Options]: crypto.html#crypto_openssl_options
[OpenSSL cipher list format documentation]: <a href="https://www.openssl.org/docs/man1.0.2/apps/ciphers.html#CIPHER-LIST-FORMAT">https://www.openssl.org/docs/man1.0.2/apps/ciphers.html#CIPHER-LIST-FORMAT</a>
[Perfect Forward Secrecy]: #tls_perfect_forward_secrecy
[完全前向保密]: #tls_perfect_forward_secrecy
[RFC 4492]: <a href="https://www.rfc-editor.org/rfc/rfc4492.txt">https://www.rfc-editor.org/rfc/rfc4492.txt</a>
[SSL_CTX_set_timeout]: <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_timeout.html">https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_timeout.html</a>
[SSL_METHODS]: <a href="https://www.openssl.org/docs/man1.0.2/ssl/ssl.html#DEALING-WITH-PROTOCOL-METHODS">https://www.openssl.org/docs/man1.0.2/ssl/ssl.html#DEALING-WITH-PROTOCOL-METHODS</a>
[Stream]: stream.html#stream_stream
[TLS Session Tickets]: <a href="https://www.ietf.org/rfc/rfc5077.txt">https://www.ietf.org/rfc/rfc5077.txt</a>
[TLS recommendations]: <a href="https://wiki.mozilla.org/Security/Server_Side_TLS">https://wiki.mozilla.org/Security/Server_Side_TLS</a>
[asn1.js]: <a href="https://npmjs.org/package/asn1.js">https://npmjs.org/package/asn1.js</a>
[modifying the default cipher suite]: #tls_modifying_the_default_tls_cipher_suite
[specific attacks affecting larger AES key sizes]: <a href="https://www.schneier.com/blog/archives/2009/07/another_new_aes.html">https://www.schneier.com/blog/archives/2009/07/another_new_aes.html</a>
[tls.Server]: #tls_class_tls_server
[<code>dns.lookup()</code>]: dns.html#dns_dns_lookup_hostname_options_callback</p>

      </div>
    </div>

    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js 中文文档 | Node.js 中文网
        </a>
      </div>
      
        <!-- [start-include:_toc.md] -->
<ul>
<li><a href="documentation.html">关于本文档</a></li>
<li><a href="synopsis.html">用法与例子</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="assert.html">断言测试</a></li>
<li><a href="async_hooks.html">异步钩子（Async Hooks）</a></li>
<li><a href="buffer.html">缓存（Buffer）</a></li>
<li><a href="addons.html">C++ 插件</a></li>
<li><a href="n-api.html">C/C++ 插件 - N-API</a></li>
<li><a href="child_process.html">子进程</a></li>
<li><a href="cluster.html">集群（Cluster）</a></li>
<li><a href="cli.html">命令行参数</a></li>
<li><a href="console.html">控制台（Console）</a></li>
<li><a href="crypto.html">加密（Crypto）</a></li>
<li><a href="debugger.html">调试器</a></li>
<li><a href="deprecations.html">废弃的 API</a></li>
<li><a href="dns.html">DNS</a></li>
<li><a href="domain.html">域（Domain）</a></li>
<li><a href="esm.html">ECMAScript 模块</a></li>
<li><a href="errors.html">错误（Errors）</a></li>
<li><a href="events.html">事件（Events）</a></li>
<li><a href="fs.html">文件系统</a></li>
<li><a href="globals.html">全局对象（Globals）</a></li>
<li><a href="http.html">HTTP</a></li>
<li><a href="http2.html">HTTP/2</a></li>
<li><a href="https.html">HTTPS</a></li>
<li><a href="inspector.html">检查工具（Inspector）</a></li>
<li><a href="intl.html">国际化</a></li>
<li><a href="modules.html">模块（Modules）</a></li>
<li><a href="net.html">网络（Net）</a></li>
<li><a href="os.html">操作系统（OS）</a></li>
<li><a href="path.html">路径（Path）</a></li>
<li><a href="perf_hooks.html">性能钩子（Performance Hooks）</a></li>
<li><a href="process.html">进程</a></li>
<li><a href="punycode.html">Punycode</a></li>
<li><a href="querystring.html">查询字符串</a></li>
<li><a href="readline.html">逐行读取</a></li>
<li><a href="repl.html">交互式解释器（REPL）</a></li>
<li><a href="stream.html">流（Stream）</a></li>
<li><a href="string_decoder.html">字符串解码</a></li>
<li><a href="timers.html">定时器（Timers）</a></li>
<li><a href="tls.html">安全传输层（TLS/SSL）</a></li>
<li><a href="tracing.html">事件跟踪（Tracing）</a></li>
<li><a href="tty.html">TTY</a></li>
<li><a href="dgram.html">UDP / 数据报</a></li>
<li><a href="url.html">URL</a></li>
<li><a href="util.html">工具集</a></li>
<li><a href="v8.html">V8</a></li>
<li><a href="vm.html">虚拟机（VM）</a></li>
<li><a href="zlib.html">压缩（ZLIB）</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="https://github.com/nodejs/node">GitHub 仓库和问题跟踪</a></li>
<li><a href="https://groups.google.com/group/nodejs">邮件列表</a></li>
</ul>
<!-- [end-include:_toc.md] -->

      
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>
